using System.Security.Principal;
using System.Web.Mvc;

namespace Songhay.Web.BiggestBox.Controllers
{
    using ModelContext;
    using Songhay.Web.Mvc.Models;

    [HandleError]
    public class ClientController : Controller
    {
        public ActionResult Client(string option)
        {
            var model = SilverlightModelContext.GetModel(this.Url);

            if(!string.IsNullOrEmpty(option) && option == "FullEmbed")
            {
                this.ViewBag.ClientViewCssClass = null;
                model.Dimensions = new Size { Width = "100%", Height = "100%" };
            }
            else
            {
                this.ViewBag.ClientViewCssClass = "container_12";
                model.Dimensions = new Size { Width = "960", Height = "600" };
            }

            return View(model);
        }

        public ActionResult HeaderDisplayData()
        {
            var appTitle = "Development Server";

            var serverName = this.Request.ServerVariables["SERVER_NAME"].ToUpper();
            var serverAddr = this.Request.ServerVariables["LOCAL_ADDR"].ToUpper();
            var subTitle = string.Format("\\\\{0} at {1}", serverName, serverAddr);

            var data = new
            {
                ServerName = string.Format("{0} ({1})", appTitle, serverName),
                Title = appTitle,
                ServerNameUnc = subTitle,
                WindowsIdentityDisplayLine = string.Format("Windows Identity: {0}", WindowsIdentity.GetCurrent().Name)
            };

            return this.Json(data, JsonRequestBehavior.AllowGet);
        }
    }
}
